
//  页面加载完毕时
$(function(){

    //  页面自适应
    function getRem(pwidth,prem){
        var html=document.getElementsByTagName('html')[0];
        var oWidth=document.body.clientWidth||document.documentElement.clientWidth;
        html.style.fontSize=oWidth/pwidth*prem+"px";
    }
    getRem(375,100);
    window.onresize=function(){
        getRem(375,100);
    };




    //  获取用户的地理位置

    getLocation();
    function getLocation()
    {
        if (navigator.geolocation)
        {

            navigator.geolocation.getCurrentPosition(showPosition);
        }
        else{
            alert('不支持手机定位');
        }
    }

    function showPosition(position){
       localStorage.lat= position.coords.latitude;
       localStorage.lng= position.coords.longitude;



       if(localStorage.lng!==''||undefined||null||'null'){
           $('.locatepng').attr('src','img/locate sucess.png');
       }


    }




     //   点击提交的时候
     $('.confirm').on('click',function(){
        if($('.address1').val()==''){
             $('#addresshade').css('display','block');
             setTimeout(function(){
                 $('#addresshade').css('display','none');
             },1000);
        }
        else if($('.zipCode').val()==''){
            $('#zipshade').css('display','block');
            setTimeout(function(){
                $('#zipshade').css('display','none');
            },1000);
        }
        else if($('.company').val()==''){
            $('#companyshade').css('display','block');
            setTimeout(function(){
                $('#companyshade').css('display','none');
            },1000);
        }
        else{

        	var formdata = new FormData();
        	formdata.append("createUser", localStorage.tel);
        	formdata.append("token", localStorage.token);
        	formdata.append("address", $('.address1').val());
        	formdata.append("doorNum", $('.address2').val());
        	formdata.append("company", $('.company').val());
        	formdata.append("zipCode", $('.zipCode').val());
        	formdata.append("buildingType", $('#buildingType option,selected').val());
        	formdata.append("lng", localStorage.lng);
        	formdata.append("lat", localStorage.lat);
        	formdata.append("country", $('#country option,selected').val());
        	formdata.append("state", $('#state option,selected').val());
        	formdata.append("city", $('#city option:selected').val());
        	
        	var length = files.length;
        	console.log(length);
        	console.log(files);
        	for(var i =0; i <length ; i++){
        		formdata.append("files",files[i]);
        	}
        
        	console.log(111)
            $.ajax({
                url:url+'/address/save',
                type:'post',
                data: formdata,
                dataType:"json",
                contentType:false,
                processData:false,
                cache :false,
                success:function(result){
                    if(result.state==0){
                         window.location.href='list.html';
                    }
                }
            });

        }
     });



    //  加入收货地址
    var arr=[];
    var data=[{"locationId":1,"address":"南山路1"},{"locationId":2,"address":"西湖区文三西"},{"locationId":3,"address":"西湖区"},{"locationId":4,"address":"11"},{"locationId":5,"address":"1"},{"locationId":6,"address":"1"},{"locationId":7,"address":"塞银国际广场"},{"locationId":8,"address":"塞银国际广场"},{"locationId":9,"address":"塞银国际广场"},{"locationId":10,"address":"1"},{"locationId":11,"address":"西湖"},{"locationId":12,"address":"赛银国际广场大楼"}];
    for(var i=0;i<data.length;i++){
        arr.push(data[i].address);
    }
    console.log(arr);
    // $.ajax({
    //     url:'http://108.175.5.139/location/select',
    //     type:'post',
    //     success:function(result){
    //         var data=result.data;
    //         for(var i=0;i<data.length;i++){
    //             arr.push(data[i].address)
    //         }
    //         console.log(arr);
    //     }
    // })














});